﻿// -------------------------------------------------------------------------
//    @FileName         :    NFMMOSnsPlayerPlugin.cpp
//    @Author           :    gaoyi
//    @Date             :    2025-02-27
//    @Email			:    445267987@qq.com
//    @Module           :    NFMMOSnsPlayerPlugin
//
// -------------------------------------------------------------------------

#include "NFMMOSnsPlayerPlugin.h"

#include <NFSnsOnlineRole.h>
#include <NFSnsDetailPartModule.h>
#include <NFSnsFriendModule.h>
#include <NFSnsFriendPart.h>
#include <NFSnsRoleDetail.h>
#include <NFTransLoadRoleDetail.h>
#include <NFTransRoleOnline.h>
#include <NFTransSaveDetailDB.h>
#include "NFSnsLoginModule.h"
#include "NFSnsPlayerModule.h"
#include "NFComm/NFPluginModule/NFIPluginManager.h"
#include <NFComm/NFObjCommon/NFTypeDefines.h>
#include "NFSnsDetailPart.h"
#include "NFTransInsertRoleDetail.h"
#include "NFSnsServer/NFSnsCommon/NFTransInsertRoleSimple.h"
#include "NFSnsServer/NFSnsCommon/NFTransSaveSimpleDb.h"

#ifdef NF_DYNAMIC_PLUGIN

NF_EXPORT void DllStartPlugin(NFIPluginManager* pm)
{
    CREATE_PLUGIN(pm, NFMMOSnsPlayerPlugin)

};

NF_EXPORT void DllStopPlugin(NFIPluginManager* pm)
{
    DESTROY_PLUGIN(pm, NFMMOSnsPlayerPlugin)
};

#endif


//////////////////////////////////////////////////////////////////////////

int NFMMOSnsPlayerPlugin::GetPluginVersion()
{
    return 0;
}

std::string NFMMOSnsPlayerPlugin::GetPluginName()
{
    return GET_CLASS_NAME(NFMMOSnsPlayerPlugin);
}

void NFMMOSnsPlayerPlugin::Install()
{
    REGISTER_MODULE_TICK(m_pObjPluginManager, NFSnsPlayerModule, NFSnsPlayerModule);
    REGISTER_MODULE(m_pObjPluginManager, NFSnsLoginModule, NFSnsLoginModule);
    REGISTER_MODULE(m_pObjPluginManager, NFSnsFriendModule, NFSnsFriendModule);
    REGISTER_MODULE(m_pObjPluginManager, NFSnsDetailPartModule, NFSnsDetailPartModule);
}

void NFMMOSnsPlayerPlugin::Uninstall()
{
    UNREGISTER_MODULE(m_pObjPluginManager, NFSnsPlayerModule, NFSnsPlayerModule);
    UNREGISTER_MODULE(m_pObjPluginManager, NFSnsLoginModule, NFSnsLoginModule);
    UNREGISTER_MODULE(m_pObjPluginManager, NFSnsFriendModule, NFSnsFriendModule);
    UNREGISTER_MODULE(m_pObjPluginManager, NFSnsDetailPartModule, NFSnsDetailPartModule);
}

bool NFMMOSnsPlayerPlugin::InitShmObjectRegister()
{
    NFServerConfig* pConfig = FindModule<NFIConfigModule>()->GetAppConfig(NF_ST_SNS_SERVER);
    NF_ASSERT(pConfig);
    uint32_t maxOnlinePlayerNum = pConfig->GetMaxOnlinePlayerNum() * 1.2;

/////////////////////////////////////////////////////////////////////////////////
    REGISTER_SHM_OBJ_WITH_HASH(NFSnsOnlineRole, maxOnlinePlayerNum);
    REGISTER_SHM_OBJ_WITH_HASH(NFSnsRoleDetail, maxOnlinePlayerNum*2);
////////////////////////////////////////trans///////////////////////////////////////////
    REGISTER_SHM_OBJ(NFTransSaveSimpleDb, maxOnlinePlayerNum);
    REGISTER_SHM_OBJ(NFTransSaveDetailDB, maxOnlinePlayerNum);
    REGISTER_SHM_OBJ(NFTransLoadRoleDetail, maxOnlinePlayerNum/10);
    REGISTER_SHM_OBJ(NFTransBatchDetailBase, 0);
    REGISTER_SHM_OBJ(NFTransRoleOnline, maxOnlinePlayerNum/10);
    REGISTER_SHM_OBJ(NFTransInsertRoleSimple, maxOnlinePlayerNum/10);
    REGISTER_SHM_OBJ(NFTransInsertRoleDetail, maxOnlinePlayerNum/10);
////////////////////////////////////////part///////////////////////////////////////////
    REGISTER_SHM_OBJ(NFSnsDetailPart, 0);
    REGISTER_SHM_OBJ(NFSnsFriendPart, maxOnlinePlayerNum*2);

    return true;
}